/**
 * output package name
 */
package com.kingdee.eas.jky.business.client;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;

import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.basedata.org.CostCenterOrgUnitInfo;
import com.kingdee.eas.jky.basedata.DeparmentInfo;
import com.kingdee.eas.jky.helper.DateHelper;

/**
 * output class name
 */
public class ConfirmationQueryUI extends AbstractConfirmationQueryUI
{
    private static final Logger logger = CoreUIObject.getLogger(ConfirmationQueryUI.class);
    
    /**
     * output class constructor
     */
    public ConfirmationQueryUI() throws Exception
    {
        super();
        timeFrom.setValue(null);
        timeTo.setValue(null);
        timeFrom.setValue(DateHelper.getFirstDayOfCurMonth());
        timeTo.setValue(DateHelper.getEndDayOfCurMonth());
        prmtDep.setValue(null);
    }

    /**
     * output storeFields method
     */
    public void storeFields()
    {
        super.storeFields();
    }
    
    public FilterInfo getFilterInfo() {
    	FilterInfo filter = new FilterInfo();
    	if(prmtDep.getValue() != null) {
    		Object[] cos = (Object[])prmtDep.getValue();
    		if(cos.length == 1) {
    			filter.getFilterItems().add(new FilterItemInfo("company.id",((CompanyOrgUnitInfo)cos[0]).getId().toString()));
    		}else {
    			Set<String> ids = new HashSet<String>();
    			for(int i=0; i<cos.length; i++) {
    				ids.add(((CompanyOrgUnitInfo)cos[i]).getId().toString());
    			}
    			filter.getFilterItems().add(new FilterItemInfo("company.id",ids,CompareType.INCLUDE));
    		}
    	}
    	if(prmtCostCenter.getValue() != null) {
    		CostCenterOrgUnitInfo ccou = (CostCenterOrgUnitInfo)prmtCostCenter.getValue();
    		filter.getFilterItems().add(new FilterItemInfo("saleCenterDep.id",ccou.getId().toString()));
    	}
    	if(prmtBusDep.getValue() != null) {
    		DeparmentInfo depar = (DeparmentInfo)prmtBusDep.getValue();
    		filter.getFilterItems().add(new FilterItemInfo("madeCenterDep.id",depar.getId().toString()));
    	}
    	if(timeFrom.getValue() != null) {
    		Calendar calendar2 = Calendar.getInstance();
			calendar2.setTime((Date)timeFrom.getValue());
			calendar2.add(Calendar.DATE, -1);
			calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DATE),23, 59, 59);
    		filter.getFilterItems().add(new FilterItemInfo("srcBillDate",calendar2.getTime(),CompareType.GREATER_EQUALS));
    	}
    	if(timeTo.getValue() != null) {
    		Calendar calendar1 = Calendar.getInstance();
    		calendar1.setTime((Date)timeTo.getValue());
    		calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DATE),23, 59, 59);
    		filter.getFilterItems().add(new FilterItemInfo("srcBillDate",calendar1.getTime(),CompareType.LESS_EQUALS));
    	}
    	
    	Set<Integer> list = new HashSet<Integer>();
    	if(xsdd.isSelected()) {
    		list.add(Integer.valueOf(1));
    	}
    	if(xsckd.isSelected()) {
    		list.add(Integer.valueOf(2));
    	}
    	if(ysd.isSelected()) {
    		list.add(Integer.valueOf(3));
    	}
    	if(skd.isSelected()) {
    		list.add(Integer.valueOf(4));
    	}
    	if(xsht.isSelected()) {
    		list.add(Integer.valueOf(5));
    	}
    	if(srqrd.isSelected()) {
    		list.add(Integer.valueOf(6));
    	}
    	if(thsqd.isSelected()) {
    		list.add(Integer.valueOf(7));
    	}
    	if(list.size() > 0) {
    		filter.getFilterItems().add(new FilterItemInfo("sourceBillType",list, CompareType.INCLUDE));
    	}
    	
    	return filter;
    }

}